package de.lmu.ifi.pst.uwejsf.framework.process;

import java.util.Map;

public abstract class BasicActivityGuardHandler implements ActivityGuardHandler {

	@Override
	public GuardEvaluationResult evaluateGuardExpression(String expression,
			Map<String, Object> scope) {
		if (expression == null)
			return GuardEvaluationResult.IS_FALLBACK;

		if (expression.trim().equalsIgnoreCase("else"))
			return GuardEvaluationResult.IS_FALLBACK;

		if (expression.matches("\\w*")) {
			// this expression tests for a button like OK
			if (scope.get("useraction_name") == null)
				return GuardEvaluationResult.FALSE;
			String actionName = (String) scope.get("useraction_name");
			return actionName.equalsIgnoreCase(expression.trim()) ? GuardEvaluationResult.TRUE
					: GuardEvaluationResult.FALSE;

		}
		
		return GuardEvaluationResult.NOT_HANDLED;
	}

}
